package com.defysoft.waukids;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import android.util.Log;

public class JsonParser implements PublicConstant, Data_Type, Custom_Data_Type {

	public static ArrayList<Bc_Student_Cus> SelectMyStudent(String message) {

		ArrayList<Bc_Student_Cus> list = new ArrayList<Custom_Data_Type.Bc_Student_Cus>();
		Bc_Student_Cus bc_Student_Cus;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				bc_Student_Cus = new Bc_Student_Cus();
				if (jsonObject != null) {
					if (jsonObject.has("PK_Stu_Code")) {
						bc_Student_Cus.PK_Stu_Code = jsonObject
								.getInt("PK_Stu_Code");
					}
					if (jsonObject.has("FK_Sch_Stu_Code")) {
						bc_Student_Cus.FK_Sch_Stu_Code = jsonObject
								.getInt("FK_Sch_Stu_Code");
					}
					if (jsonObject.has("FK_Cla_Stu_Code")) {
						bc_Student_Cus.FK_Cla_Stu_Code = jsonObject
								.getInt("FK_Cla_Stu_Code");
					}
					if (jsonObject.has("FK_Bea_Stu_Code")) {
						bc_Student_Cus.FK_Bea_Stu_Code = jsonObject
								.getInt("FK_Bea_Stu_Code");
					}
					if (jsonObject.has("Stu_Name")) {
						bc_Student_Cus.Stu_Name = jsonObject
								.getString("Stu_Name");
					}
					if (jsonObject.has("Stu_Birth")) {
						bc_Student_Cus.Stu_Birth = jsonObject
								.getString("Stu_Birth");
					}
					if (jsonObject.has("Stu_Info")) {
						bc_Student_Cus.Stu_Info = jsonObject
								.getString("Stu_Info");
					}
					if (jsonObject.has("Stu_Photo")) {
						bc_Student_Cus.Stu_Photo = jsonObject
								.getString("Stu_Photo");
					}
					if (jsonObject.has("classname")) {
						bc_Student_Cus.classname = jsonObject
								.getString("classname");
					}
				}
				list.add(bc_Student_Cus);
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}

	public static BC_SCHOOL_CLASS SelectClass(String message) {

		BC_SCHOOL_CLASS bc_School_Class = new BC_SCHOOL_CLASS();
		try {
			JSONObject jsonObject = new JSONObject(message);
			if (jsonObject != null) {
				if (jsonObject.has("PK_Cla_Code")) {
					bc_School_Class.PK_Cla_Code = jsonObject
							.getInt("PK_Cla_Code");
				}
				if (jsonObject.has("FK_Sch_Cla_Code")) {
					bc_School_Class.FK_Sch_Cla_Code = jsonObject
							.getInt("FK_Sch_Cla_Code");
				}
				if (jsonObject.has("Cla_Info")) {
					bc_School_Class.Cla_Info = jsonObject.getString("Cla_Info");
				}
				if (jsonObject.has("Cla_Name")) {
					bc_School_Class.Cla_Name = jsonObject.getString("Cla_Name");
				}
			}

		} catch (Exception e) {
			return bc_School_Class;
		}
		return bc_School_Class;
	}
	
	public static ArrayList< BC_SCHOOL> SelectSchool(String message) {

		ArrayList<BC_SCHOOL> list = new ArrayList<BC_SCHOOL>();
		BC_SCHOOL bc_School;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				bc_School = new BC_SCHOOL();
				if (jsonObject != null) {
					if (jsonObject.has("PK_Sch_Code")) {
						bc_School.PK_Sch_Code = jsonObject
								.getInt("PK_Sch_Code");
					}
					if (jsonObject.has("FK_Add_Sch_Code")) {
						bc_School.FK_Add_Sch_Code = jsonObject
								.getInt("FK_Add_Sch_Code");
					}
					if (jsonObject.has("Sch_Name")) {
						bc_School.Sch_Name = jsonObject
								.getString("Sch_Name");
					}
					if (jsonObject.has("Sch_Info")) {
						bc_School.Sch_Info = jsonObject
								.getString("Sch_Info");
					}
					if (jsonObject.has("Sch_Add")) {
						bc_School.Sch_Add = jsonObject
								.getString("Sch_Add");
					}
					
			
				}
				list.add(bc_School);
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}


	public static ArrayList<BC_NOTICE> SelectNotice(String message) { // 공지사항.

		ArrayList<BC_NOTICE> list = new ArrayList<BC_NOTICE>();
		BC_NOTICE bc_Notice;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				bc_Notice = new BC_NOTICE();
				if (jsonObject != null) {
					if (jsonObject.has("PK_Not_Code")) {
						bc_Notice.PK_Not_Code = jsonObject
								.getInt("PK_Not_Code");
					}
					if (jsonObject.has("FK_Sch_Not_Code")) {
						bc_Notice.FK_Sch_Not_Code = jsonObject
								.getInt("FK_Sch_Not_Code");
					}
					if (jsonObject.has("FK_Cla_Not_Code")) {
						bc_Notice.FK_Cla_Not_Code = jsonObject
								.getInt("FK_Cla_Not_Code");
					}
					if (jsonObject.has("Not_Name")) {
						bc_Notice.Not_Name = jsonObject.getString("Not_Name");
					}
					if (jsonObject.has("Not_Sub")) {
						bc_Notice.Not_Sub = jsonObject.getString("Not_Sub");
					}
					if (jsonObject.has("Not_Date")) {
						bc_Notice.Not_Date = jsonObject.getString("Not_Date");
					}
					if (jsonObject.has("PK_Mem_Not_Email")) {
						bc_Notice.PK_Mem_Not_Email = jsonObject
								.getString("PK_Mem_Not_Email");
					}
					if (jsonObject.has("Not_WriteName")) {
						bc_Notice.Not_WriteName = jsonObject
								.getString("Not_WriteName");
					}
					if (jsonObject.has("Not_Photo")) {
						bc_Notice.Not_Photo = jsonObject.getString("Not_Photo");
					}
					if (jsonObject.has("Not_Rage")) {
						bc_Notice.Not_Rage = jsonObject.getString("Not_Rage");
					}
				}
				list.add(bc_Notice);
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}

	public static ArrayList<Bc_Student_Att> AttendSelectMember(String message) {

		ArrayList<Bc_Student_Att> list = new ArrayList<Bc_Student_Att>();
		Bc_Student_Att bc_Student_Att;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				bc_Student_Att = new Bc_Student_Att();
				if (jsonObject != null) {
					if (jsonObject.has("PK_Stu_Code")) {
						bc_Student_Att.PK_Stu_Code = jsonObject
								.getInt("PK_Stu_Code");
					}

					if (jsonObject.has("FK_Sch_Stu_Code")) {
						bc_Student_Att.FK_Sch_Stu_Code = jsonObject
								.getInt("FK_Sch_Stu_Code");
					}
					if (jsonObject.has("FK_Cla_Stu_Code")) {
						bc_Student_Att.FK_Cla_Stu_Code = jsonObject
								.getInt("FK_Cla_Stu_Code");
					}
					if (jsonObject.has("FK_Bea_Stu_Code")) {
						bc_Student_Att.FK_Bea_Stu_Code = jsonObject
								.getInt("FK_Bea_Stu_Code");
					}
					if (jsonObject.has("Stu_Name")) {
						bc_Student_Att.Stu_Name = jsonObject
								.getString("Stu_Name");
					}
					if (jsonObject.has("cla_name")) {
						bc_Student_Att.cla_name = jsonObject
								.getString("cla_name");
					}
					if (jsonObject.has("Stu_Birth")) {
						bc_Student_Att.Stu_Birth = jsonObject
								.getString("Stu_Birth");
					}
					if (jsonObject.has("Stu_Info")) {
						bc_Student_Att.Stu_Info = jsonObject
								.getString("Stu_Info");
					}
					if (jsonObject.has("Stu_Photo")) {
						bc_Student_Att.Stu_Photo = jsonObject
								.getString("Stu_Photo");
					}
					if (jsonObject.has("check")) {
						bc_Student_Att.check = jsonObject.getString("check");
					}

				}
				list.add(bc_Student_Att);
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}

	public static BC_NOTICE NoticeDetail(String message) {

		BC_NOTICE bc_Notice = new BC_NOTICE();
		try {
			JSONObject jsonObject = new JSONObject(message);
			if (jsonObject != null) {
				if (jsonObject.has("PK_Not_Code")) {
					bc_Notice.PK_Not_Code = jsonObject.getInt("PK_Not_Code");
				}
				if (jsonObject.has("FK_Sch_Not_Code")) {
					bc_Notice.FK_Sch_Not_Code = jsonObject
							.getInt("FK_Sch_Not_Code");
				}
				if (jsonObject.has("FK_Cla_Not_Code")) {
					bc_Notice.FK_Cla_Not_Code = jsonObject
							.getInt("FK_Cla_Not_Code");
				}
				if (jsonObject.has("Not_Name")) {
					bc_Notice.Not_Name = jsonObject.getString("Not_Name");
				}
				if (jsonObject.has("Not_Sub")) {
					bc_Notice.Not_Sub = jsonObject.getString("Not_Sub");
				}
				if (jsonObject.has("Not_Date")) {
					bc_Notice.Not_Date = jsonObject.getString("Not_Date");
				}
				if (jsonObject.has("PK_Mem_Not_Email")) {
					bc_Notice.PK_Mem_Not_Email = jsonObject
							.getString("PK_Mem_Not_Email");
				}
				if (jsonObject.has("Not_WriteName")) {
					bc_Notice.Not_WriteName = jsonObject
							.getString("Not_WriteName");
				}
				if (jsonObject.has("Not_Photo")) {
					bc_Notice.Not_Photo = jsonObject.getString("Not_Photo");
				}
				if (jsonObject.has("Not_Rage")) {
					bc_Notice.Not_Rage = jsonObject.getString("Not_Rage");
				}
			}

		} catch (Exception e) {
			return bc_Notice;
		}
		return bc_Notice;
	}

	public static ArrayList<BC_ATTEND> AttendSelectList(String message) {

		ArrayList<BC_ATTEND> list = new ArrayList<BC_ATTEND>();
		BC_ATTEND bc_aAttend;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				bc_aAttend = new BC_ATTEND();
				if (jsonObject != null) {
					if (jsonObject.has("PK_Att_Code")) {
						bc_aAttend.PK_Att_Code = jsonObject
								.getInt("PK_Att_Code");
					}
					if (jsonObject.has("FK_Sch_Att_Code")) {
						bc_aAttend.FK_Sch_Att_Code = jsonObject
								.getInt("FK_Sch_Att_Code");
					}
					if (jsonObject.has("FK_Cla_Att_Code")) {
						bc_aAttend.FK_Cla_Att_Code = jsonObject
								.getInt("FK_Cla_Att_Code");
					}
					if (jsonObject.has("FK_Stu_Att_Code")) {
						bc_aAttend.FK_Stu_Att_Code = jsonObject
								.getInt("FK_Stu_Att_Code");
					}
					if (jsonObject.has("Att_Date")) {
						bc_aAttend.Att_Date = jsonObject.getString("Att_Date");
					}
					if (jsonObject.has("Att_Check")) {
						bc_aAttend.Att_Check = jsonObject.getInt("Att_Check");
					}
					if (jsonObject.has("Att_Reason")) {
						bc_aAttend.Att_Reason = jsonObject
								.getString("Att_Reason");
					}

				}
				list.add(bc_aAttend);
			}
		} catch (Exception e) {
			return null;
		}
		return list;
	}

	public static BC_ATTEND AttendSelectFetch(String message) {

		BC_ATTEND bc_aAttend= new BC_ATTEND();
		try {
			JSONObject jsonObject = new JSONObject(message);
			
			if (jsonObject != null) {
				if (jsonObject.has("PK_Att_Code")) {
					bc_aAttend.PK_Att_Code = jsonObject.getInt("PK_Att_Code");
				}
				if (jsonObject.has("FK_Sch_Att_Code")) {
					bc_aAttend.FK_Sch_Att_Code = jsonObject
							.getInt("FK_Sch_Att_Code");
				}
				if (jsonObject.has("FK_Cla_Att_Code")) {
					bc_aAttend.FK_Cla_Att_Code = jsonObject
							.getInt("FK_Cla_Att_Code");
				}
				if (jsonObject.has("FK_Stu_Att_Code")) {
					bc_aAttend.FK_Stu_Att_Code = jsonObject
							.getInt("FK_Stu_Att_Code");
				}
				if (jsonObject.has("Att_Date")) {
					bc_aAttend.Att_Date = jsonObject.getString("Att_Date");
				}
				if (jsonObject.has("Att_Check")) {
					bc_aAttend.Att_Check = jsonObject.getInt("Att_Check");
				}
				if (jsonObject.has("Att_Reason")) {
					bc_aAttend.Att_Reason = jsonObject.getString("Att_Reason");
				}

			}
		} catch (Exception e) {
			return bc_aAttend;
		}
		return bc_aAttend;
	}
	
	public static Bc_Student_Che StudentDetail(String message) {	//원생정보
		Bc_Student_Che bc_Student_Che = new Bc_Student_Che();
		try {
			JSONObject jsonObject = new JSONObject(message);
			if (jsonObject != null) {
				if (jsonObject.has("PK_Stu_Code")) {bc_Student_Che.PK_Stu_Code = jsonObject.getInt("PK_Stu_Code");}
				if (jsonObject.has("FK_Sch_Stu_Code")) {bc_Student_Che.FK_Sch_Stu_Code = jsonObject.getInt("FK_Sch_Stu_Code");}
				if (jsonObject.has("FK_Cla_Stu_Code")) {bc_Student_Che.FK_Cla_Stu_Code = jsonObject.getInt("FK_Cla_Stu_Code");}
				if (jsonObject.has("FK_Bea_Stu_Code")) {bc_Student_Che.FK_Bea_Stu_Code = jsonObject.getInt("FK_Bea_Stu_Code");}
				if (jsonObject.has("Stu_Name")) {bc_Student_Che.Stu_Name = jsonObject.getString("Stu_Name");}
				if (jsonObject.has("Stu_Birth")) {bc_Student_Che.Stu_Birth = jsonObject.getString("Stu_Birth");}
				if (jsonObject.has("Stu_Info")) {bc_Student_Che.Stu_Info = jsonObject.getString("Stu_Info");}
				if (jsonObject.has("Stu_Photo")) {bc_Student_Che.Stu_Photo = jsonObject.getString("Stu_Photo");}
				if (jsonObject.has("schoolname")) {bc_Student_Che.schoolname = jsonObject.getString("schoolname");}
				if (jsonObject.has("schoolclass")) {bc_Student_Che.schoolclass = jsonObject.getString("schoolclass");}
			}
		} catch (Exception e) {
			return bc_Student_Che;
		}
		return bc_Student_Che;
	}
}// CLASS_END
